﻿using Microsoft.AspNetCore.Mvc;
using Shop.ProductService.Services;
using Shop.ProductService.Services.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Shop.ProductService.Controllers
{
    /// <summary>
    /// 商品控制器
    /// </summary>
    [ApiController]
    [Route("api/app/product")]
    public class ProductController:AbpController,IProductService
    {
        public IProductService productService { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("id")]
        public async Task DeleteAsync(Guid id)
        {
            await productService.DeleteAsync(id);
        }

        /// <summary>
        /// 创建商品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<ProductDto> CreateAsync([FromBody] ProductDto input)
        {
            try
            {

                var result = await productService.CreateAsync(input);
                return result;
            }
            catch (Exception e)
            {

                throw;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("id")]
        public async Task<ProductDto> GetAsync(Guid id)
        { 
            return await productService.GetAsync(id);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return await productService.GetListAsync(input);
        }

        /// <summary>
        /// 查询商品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetProducts")]
        public async Task<List<ProductDto>> GetProductsAsync()
        {
            var list = await productService.GetProductsAsync();
            return list;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
        {
           return await productService.UpdateAsync(id, input);
        }

          
    }
}
